home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / cachemon.zip / CACHEREP.PAS < prev    next >
Pascal/Delphi Source File  |  1990-03-14  |  4KB  |  164 lines

  1. program cacherep;
  2.  
  3. { Program to print cache report; needs to have CACHEMON loaded before
  4.   and after the disk cache }
  5.  
  6. uses opstring,opinline;
  7. type
  8.   cachemon_ptr = ^cachemon_rec;
  9.   cachemon_rec = record
  10.     read_count,
  11.     read_sects,
  12.     write_count,
  13.     write_sects : longint;
  14.     drive_id : byte;
  15.     more_sig : longint;
  16.     my_name  : string[8];
  17.   end;
  18.  
  19.   buftype = array[0..$8000+30] of char;
  20.  
  21. var
  22.   bt : btable;
  23.  
  24. const
  25.   signature:string[32] = 'CACHEMON 1.0 disk access monitor';
  26.   more_sig : longint = $12345678;
  27.  
  28. function find_driver(prev:cachemon_ptr):cachemon_ptr;
  29. var
  30.   buf : ^buftype;
  31.   match : word;
  32.   monitor : cachemon_ptr;
  33.   segment,offset : word;
  34.  
  35. begin
  36.   segment := seg(prev^);
  37.   offset := ofs(prev^);
  38.   repeat
  39.     buf := ptr(segment,offset);
  40.     if offset < sizeof(buftype) then
  41.       match := bmsearch(buf^, sizeof(buftype)-offset, bt, signature)
  42.     else
  43.       match := $FFFF;
  44.  
  45.     if match <> $FFFF then
  46.     begin
  47.       monitor := ptr(segment,match+offset+length(signature));
  48.       if monitor^.more_sig = more_sig then
  49.       begin
  50.         find_driver := monitor;
  51.         exit;
  52.       end;
  53.       offset := offset + match + length(signature);
  54.     end
  55.     else
  56.     begin
  57.       inc(segment, $800);
  58.       offset := 0;
  59.     end;
  60.   until segment > $f000;
  61.   find_driver := nil;
  62. end;
  63.  
  64. procedure syntax_exit;
  65. begin
  66.   writeln('Syntax:  CACHEREP [/R]');
  67.   writeln(' will search memory for CACHEMON monitors, and print results.');
  68.   writeln(' /R option will reset all counters to 0.');
  69.   halt;
  70. end;
  71.  
  72. function pct(num,den:longint):integer;
  73. begin
  74.   if den = 0 then
  75.     pct := 0
  76.   else
  77.     pct := (100*num + den div 2) div den;
  78. end;
  79.  
  80. const
  81.   tablesize = 10;
  82.  
  83. var
  84.   monitor : cachemon_ptr;
  85.   monitor_seg : word;
  86.   i,num : integer;
  87.   resetcounts : boolean;
  88.   table : array[1..tablesize] of cachemon_ptr;
  89.   maxreads : longint;
  90.   last_loaded : integer;
  91.  
  92. begin
  93.   writeln('CACHEREP v. 1.0 - copyright (c) 1990 D.J. Murdoch.');
  94.   if paramcount > 1 then
  95.     syntax_exit;
  96.   if paramcount = 1 then
  97.   begin
  98.     if stupcase(paramstr(1)) <> '/R' then
  99.       syntax_exit;
  100.     resetcounts := true;
  101.   end
  102.   else
  103.     resetcounts := false;
  104.  
  105.   bmmaketable(signature,bt);
  106.  
  107.   monitor := nil;
  108.   num := 0;
  109.  
  110.   { Find the monitors }
  111.  
  112.   repeat
  113.     monitor := find_driver(monitor);
  114.     if monitor <> nil then
  115.     begin
  116.       monitor_seg := seg(monitor^) + ofs(monitor^) div 16;
  117.       if (monitor_seg < prefixseg) or (monitor_seg > seg(freeptr^)+$1000) then
  118.       begin
  119.         inc(num);
  120.         table[num] := monitor;
  121.       end;
  122.     end;
  123.   until (monitor=nil) or (num=tablesize);
  124.  
  125.   if num = 0 then
  126.   begin
  127.     writeln('No cache monitors found!');
  128.     halt;
  129.   end;
  130.  
  131.   { find the one with the largest number of reads }
  132.   maxreads := 0;
  133.   last_loaded := 1;
  134.   for i:=1 to num do
  135.     if table[i]^.read_count > maxreads then
  136.     begin
  137.       last_loaded := i;
  138.       maxreads := table[i]^.read_count;
  139.     end;
  140.  
  141.   writeln(' #     Name     Reads  %   Sectors  %     Writes  %   Sectors  %');
  142.   for i:=1 to num do
  143.     with table[i]^ do
  144.       writeln(i:2, my_name:9,
  145.         read_count:10, pct(read_count,table[last_loaded]^.read_count):4,
  146.         read_sects:8, pct(read_sects,table[last_loaded]^.read_sects):5,
  147.        write_count:10,pct(write_count,table[last_loaded]^.write_count):4,
  148.        write_sects:8,pct(write_sects,table[last_loaded]^.write_sects):5);
  149.  
  150.   if resetcounts then
  151.   begin
  152.     writeln('Resetting all counters to 0.');
  153.     for i:=1 to num do
  154.       with table[i]^ do
  155.       begin
  156.         read_count := 0;
  157.         read_sects := 0;
  158.         write_count := 0;
  159.         write_sects := 0;
  160.       end;
  161.   end;
  162.  
  163. end.
  164.